package A1_贪心算法;

import java.util.Arrays;

public class LC_135分发糖果_初始值 {
    public int candy(int[] ratings) {
        int[] cnady=new int[ratings.length];
        for(int i=0;i<ratings.length;i++){
            if(i>0 && ratings[i]>ratings[i-1])
                cnady[i]=cnady[i-1]+1;
            else
                cnady[i]=1;
        }
        for(int i=ratings.length-2;i>=0;i--)
            if(ratings[i]>ratings[i+1])
                cnady[i]=Math.max(cnady[i+1]+1,cnady[i]);
        return Arrays.stream(cnady).sum();
    }
}
